package com.bootdo.hotel.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ModelAttribute;
import com.bootdo.common.controller.BaseController;
import com.bootdo.hotel.domain.HotelRoomType;
import com.bootdo.hotel.service.HotelRoomTypeService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 酒店房型
 * 
 * @author haojiangbo
 * @email 2100272728@qq.com
 * @date 2019-10-18 11:10:03
 */
 
@Controller
@RequestMapping("/hotel/hotelRoomType")
public class HotelRoomTypeController extends BaseController{


	@Autowired
	private HotelRoomTypeService hotelRoomTypeService;

	@ModelAttribute
	public HotelRoomType get(@RequestParam(required=false) Long id) {
		if (id != null){
			return hotelRoomTypeService.get(id);
		}else{
			return new HotelRoomType();
		}
	}


	
	//insert into sys_menu(parent_id,name,url,perms,type)  values (149,'测试','/hotel/hotelRoomType','hotel:hotelRoomType:hotelRoomType',1)
	//insert into sys_menu(parent_id,name,url,perms,type)  values (160,'修改','','hotel:hotelRoomType:edit',2)
	//type 0是分类菜单 1是小菜但 2是按钮
	@GetMapping()
	@RequiresPermissions("hotel:hotelRoomType:hotelRoomType")	
	String HotelRoomType(HotelRoomType hotelRoomType,HttpServletRequest request,HttpServletResponse response){
	    return "hotel/hotelRoomType/hotelRoomType";
	}
	
	@ResponseBody
	@PostMapping("/list")
	@RequiresPermissions("hotel:hotelRoomType:hotelRoomType")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		if(!isAdmin()){
			query.put("userId", getUserId());
		}
		List<HotelRoomType> hotelRoomTypeList = hotelRoomTypeService.list(query);
		int total = hotelRoomTypeService.count(query);
		PageUtils pageUtils = new PageUtils(hotelRoomTypeList, total);
		return pageUtils;
	}

	/**
	 * /hotel/hotelRoomType/getHotelRoomTypeList
	 * @param params
	 * @return
	 */
	@ResponseBody
	@PostMapping("/getHotelRoomTypeList")
	@RequiresPermissions("hotel:hotelRoomType:hotelRoomType")
	public R getHotelRoomTypeList(@RequestParam Map<String, Object> params){
		//查询列表数据
		if(!isAdmin()){
			params.put("userId", getUserId());
		}
		List<HotelRoomType> hotelRoomTypeList = hotelRoomTypeService.list(params);
		return R.ok().put("l",hotelRoomTypeList);
	}



	@GetMapping("/add")
	@RequiresPermissions("hotel:hotelRoomType:edit")
	String add(HotelRoomType hotelRoomType,HttpServletRequest request,HttpServletResponse response){
	    return "hotel/hotelRoomType/hotelRoomTypeedit";
	}

	@PostMapping("/getById")
	@ResponseBody
	R getById(HotelRoomType hotelRoomType) {
		return R.ok().put("i",hotelRoomType);
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("hotel:hotelRoomType:edit")
	public R save( HotelRoomType hotelRoomType){
		if(!isAdmin()){
			if(null == hotelRoomType.getUserId()){
				hotelRoomType.setUserId(getUserId());
				hotelRoomType.setUserName(getUsername());
			}
		}
		if(hotelRoomTypeService.save(hotelRoomType)>0){
			return R.ok();
		}
		return R.error();
	}
	
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("hotel:hotelRoomType:edit")
	public R remove( Long id){
		if(hotelRoomTypeService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("hotel:hotelRoomType:edit")
	public R remove(@RequestParam("ids[]") Long[] ids){
		hotelRoomTypeService.batchRemove(ids);
		return R.ok();
	}
	
}